package educrypt.gui.components;

import java.awt.Component;

import javax.swing.JPanel;
import javax.swing.JScrollPane;

public abstract class EducryptPanel extends JPanel {
	private static final long serialVersionUID = -8793785283171960256L;

	public EducryptPanel() {

	}

	public void setPanelEnabled(boolean b) {
		setJPanelEnabled(this, b);
	}

	// Method that can manage composed panels
	private void setJPanelEnabled(JPanel p, boolean b) {
		Component[] components = p.getComponents();
		for (Component c : components) {
			c.setEnabled(b);
			if (c instanceof JPanel) {
				setJPanelEnabled((JPanel) c, b);
			}
			if (c instanceof JScrollPane) {
				JScrollPane scp = (JScrollPane) c;
				scp.getViewport().getView().setEnabled(b);
			}
		}
	}

	public void setPanelVisible(boolean b) {
		Component[] components = this.getComponents();
		for (Component c : components) {
			c.setVisible(b);
		}
	}
}
